'use strict';

/**
 * @name 检测数据有效性
 */
angular.module('metalabPartnerApp')
    .factory('MetaForm', [function () {

    var formCheck = {};

    formCheck.checkboxAtLeastOne = function (object) {
    	return Object.keys(object).some(function (key) {
		    return object[key];
		});
    };

    return formCheck;
	}])
	.directive("biggerThan", function() {
	    return {
	        require: "ngModel",
	        scope: {
	            otherModelValue: "=biggerThan"
	        },
	        link: function(scope, element, attributes, ngModel) {

	            ngModel.$validators.biggerThan = function(modelValue) {
	                return modelValue >= scope.otherModelValue;
	            };

	            scope.$watch("otherModelValue", function() {
	                ngModel.$validate();
	            });
	        }
	    };
	});
